package com.my.radio;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.graphics.Color;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class PTYListViewAdapter extends BaseAdapter {
	private List<View> PTYTypeList;
	private final String[] mPty_data = { "NONE", "NEWS", "AFFAIRS", "INFO", "SPORTS", "EDUCATE", "DRAMA", "CULTURE", "SCIENCE", "VARIED",
			"POP M", "ROCK M", "EASY M", "LIGHT M", "CLASSICS", "OTHER M", "WEATHERE", "FINANCE", "CHILDREN", "SOCIAL", "RELIGION",
			"PHONE IN", "TRAVEL", "LEISURE", "JAZZ", "COUNTRY", "NATION M", "OLDIES", "FOLK M", "DOCUMENT", "TEST" };
	private static final int PTY_MAX = 31;
	public PTYListViewAdapter(Activity context, int id) {
		PTYTypeList = new ArrayList<View>(PTY_MAX);
		View v;
		TextView tv;

	    LayoutInflater inflater = context.getLayoutInflater();
	       
		for(int i=0;i<PTY_MAX;i++){
			v = inflater.inflate(id, null, false);
			tv = (TextView) v.findViewById(R.id.list_text);
			tv.setText(mPty_data[i]);
			PTYTypeList.add(v);
		}
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return PTY_MAX;
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	public View getView(int position, View convertView, ViewGroup parent) {		
		return PTYTypeList.get(position);
	}
	

	private void setTextColor(View v, int color){
		if (v == null)
			return;
		
		TextView tv = (TextView) v.findViewById(R.id.list_text);
		if (tv != null) {
			tv.setTextColor(color);
			v.postInvalidate();
		}
	}
	private int mPos = -1;
	public void setSelectItem(int pos) {
		if (PTYTypeList == null || pos >= PTYTypeList.size()){
			return;
		}
		
		if (mPos != pos) {
			setTextColor(PTYTypeList.get(pos), Color.BLUE);			

			if (mPos != -1) {
				setTextColor(PTYTypeList.get(pos), Color.WHITE);
			}

			mPos = pos;
		}
	}

}
